package com.lc1993929;

import com.lc1993929.dao.AbstractRepository;
import com.lc1993929.dao.PersonRepository;
import com.lc1993929.entity.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * Created by LiuChang on 2017/3/30.
 */
public class MongoTest {

    private static Logger logger = LoggerFactory.getLogger(MongoTest.class);

    private AbstractRepository pr = null;


    public void init() {

        ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath*:applicationContext.xml");
        pr = (PersonRepository) ctx.getBean("personRepository");


    }

    public void insert() {

        Person p = new Person("cuiran", 27);
        pr.insert(p);
    }

    public void findOne() {
        String id = "58ddd075488e65f38f548611";
        Person p = pr.findOne(id);
        logger.debug(p.toString());
    }


    public void listAll() {

        List<Person> list = pr.findAll();

        for (Person p : list) {
            logger.debug(p.toString());
        }


    }


    public void start() {
        init();

//        insert();
        listAll();

//        findOne();
    }

    public static void main(String[] args) {
        MongoTest t = new MongoTest();
        t.start();
    }

}
